﻿package tv.colmeia.game.assets {
	/**
	* ...
	* @author Martin Fabichak @ colmeia.tv
	*/
	
	import flash.display.Sprite;
	import flash.events.Event;
	import org.cove.ape.RectangleParticle;
	import tv.colmeia.game.assets.sprites.AmbulanciaSprite;
	import caurina.transitions.Tweener;
	import org.cove.ape.CollisionEvent;
	
	public class Ambulancia extends RectangleParticle{
		private var _ponto:Sprite;
		
		public function Ambulancia(sprite:AmbulanciaSprite, p:Sprite) {
			_ponto = p;
			super(sprite.x + sprite.width/2, sprite.y+sprite.height/2, sprite.width, sprite.height);
			this.collidable = true;
			this.sprite.name = "ambulancia";
			this.setDisplay(sprite);
			this.addEventListener(CollisionEvent.COLLIDE, collide);
		}
		private function collide(e:CollisionEvent):void {
			if ((e.collidingItem.visible))	{
				e.collidingItem.visible = false;
				_ponto.visible = true;
				_ponto.alpha = 0;
				dispatchEvent(new Event(Event.COMPLETE));
				Tweener.addTween(_ponto, { alpha:1, time:1, onComplete:function () {
					_ponto.visible = false;
				} } ) 
			}
		}
	}
	
}